$(() => {

    //渲染出生日期
    layui.use(function () {
        const laydate = layui.laydate;
        laydate.render({
            elem: "#birthday",
            type: "date"
        });
    });
});

function submit(cb = $.noop) {
    let stuId = $("#stuId").val();
    let name = $("#name").val();
    let pinyin = $("#pinyin").val();
    let birthday = $("#birthday").val();
    let phone = $("#phone").val();
    let wechat = $("#wechat").val();
    let sex = $(":input[name=sex]:checked").val();

    //前端校验：js校验
    if (stuId.trim() === "") {
        layer.msg("学号不可为空");
        return;
    }
    if (name.trim() === "") {
        layer.msg("姓名不可为空");
        return;
    }
    let pat = /^\d{4}-\d{2}-\d{2}$/;
    if (!pat.test(birthday)) {
        layer.msg("出生日期格式不正确");
        return;
    }
    pat = /^\d{11}$/;
    if (!pat.test(phone)) {
        layer.msg("手机号格式不正确");
        return;
    }

    $.ajax({
        url: ctx + "/admin/student/add",
        method: "post",
        data: {
            stuId,
            name,
            pinyin,
            birthday,
            phone,
            wechat,
            sex
        },
        success(resp) {
            cb(resp.success);
        }
    });


}